﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Xml;

namespace FCNS.Calendar
{
    class Language
    {
        Hashtable strings = new Hashtable();

        public Language(string language)
        {
            LoadLanguage(language);
        }

        public void LoadLanguage(string language)
        {
            strings.Clear();
            XmlTextReader reader = null;
            
            try
            {
                reader = new XmlTextReader(AppDomain.CurrentDomain.BaseDirectory + "Language\\" + language + ".lan");

                string name, value;
                name = value = null;
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            name = reader.Name;
                            break;
                        case XmlNodeType.Text:
                            value = reader.Value;
                            break;
                        case XmlNodeType.EndElement:
                            strings.Add(name,value);
                            name = value = null;
                            break;
                    }
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }

        public string GetString(string name)
        {
            return (string)strings[name];
        }
    }
}
